package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.DefinitionAuditor;
import com.ruoyi.business.service.IDefinitionAuditorService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 节点审核人Controller
 * 
 * @author x1ao
 * @date 2021-07-20
 */
@Controller
@RequestMapping("/business/definitionAuditor")
public class DefinitionAuditorController extends BaseController
{
    private String prefix = "business/definitionAuditor";

    @Autowired
    private IDefinitionAuditorService definitionAuditorService;

    @RequiresPermissions("business:definitionAuditor:view")
    @GetMapping("/{definitionId}")
    public String definitionAuditor(@PathVariable("definitionId") Long definitionId, ModelMap mmap)
    {
        mmap.put("definitionId", definitionId);
        return prefix + "/definitionAuditor";
    }

    /**
     * 查询节点审核人列表
     */
    @RequiresPermissions("business:definitionAuditor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DefinitionAuditor definitionAuditor)
    {
        startPage();
        List<DefinitionAuditor> list = definitionAuditorService.selectDefinitionAuditorList(definitionAuditor);
        return getDataTable(list);
    }

    /**
     * 导出节点审核人列表
     */
    @RequiresPermissions("business:definitionAuditor:export")
    @Log(title = "节点审核人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DefinitionAuditor definitionAuditor)
    {
        List<DefinitionAuditor> list = definitionAuditorService.selectDefinitionAuditorList(definitionAuditor);
        ExcelUtil<DefinitionAuditor> util = new ExcelUtil<DefinitionAuditor>(DefinitionAuditor.class);
        return util.exportExcel(list, "节点审核人数据");
    }

    /**
     * 新增节点审核人
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存节点审核人
     */
    @RequiresPermissions("business:definitionAuditor:add")
    @Log(title = "节点审核人", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DefinitionAuditor definitionAuditor)
    {
        return toAjax(definitionAuditorService.insertDefinitionAuditor(definitionAuditor));
    }

    /**
     * 修改节点审核人
     */
    @GetMapping("/edit/{nodeId}")
    public String edit(@PathVariable("nodeId") Long nodeId, ModelMap mmap)
    {
        DefinitionAuditor definitionAuditor = definitionAuditorService.selectDefinitionAuditorById(nodeId);
        mmap.put("definitionAuditor", definitionAuditor);
        return prefix + "/edit";
    }

    /**
     * 修改保存节点审核人
     */
    @RequiresPermissions("business:definitionAuditor:edit")
    @Log(title = "节点审核人", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DefinitionAuditor definitionAuditor)
    {
        return toAjax(definitionAuditorService.updateDefinitionAuditor(definitionAuditor));
    }

    /**
     * 删除节点审核人
     */
    @RequiresPermissions("business:definitionAuditor:remove")
    @Log(title = "节点审核人", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(definitionAuditorService.deleteDefinitionAuditorByIds(ids));
    }
}
